"""
使用requests.session来完成gitee登陆，并获取需要登陆后才能访问的页面
1、使用session发送登录请求
   需要有请求头、请求数据等
2、使用session发送登陆后才能看到的页面
   只要加请求头user-Agent即可，session状态保持
"""
import re

import requests

session = requests.session()
url_login = "https://gitee.com/login"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36"
}

data = {
    "encrypt_key": "password",
    "utf8": "✓",
    "authenticity_toke": "vjr4PUGLq0NBF3X00KDEjTtlQ97Stl5z1DHskI3L95U=",
    "redirect_to_url": "",
    "user[login]": "zjitc_pyt@sina.com",
    "encrypt_data[user[password]]": "panyiting5",
    "user[remember_me]": "0"
}

r = session.post(url_login, headers=headers, data=data)
print(r.status_code)
print(r.content.decode())

url = 'https://gitee.com/pyt5/projects'
response = session.get(url, headers=headers)
print(response.content.decode())
